<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:nws="http://tecnologie-web.studenti.math.unipd.it/tecweb/~ccardin/"
    exclude-result-prefixes="nws">
        
<xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes' omit-xml-declaration='yes'/>
    <xsl:variable name="fromDate" select="'__YEAR__-01-01T00:00:00'"/>
    <xsl:variable name="toDate" select="'__YEAR__-12-31T23:59:59'"/>
    
    <xsl:template match="/">
		<div id="news">
            <xsl:for-each select="nws:news/nws:newsItem">
				<xsl:sort select="nws:insertDateTime" order="descending"/>
                <!-- Controllo che la data della news sia più recente di "fromDate e meno recente di toDate"-->
                <xsl:if test="(number(translate(nws:insertDateTime,'-T:',''))-number(translate($fromDate,'-T:',''))>=0) and
                              not(number(translate(nws:insertDateTime,'-T:',''))-number(translate($toDate,'-T:',''))>0)">
                    <xsl:apply-templates select="."/>
                </xsl:if>
            </xsl:for-each>
        </div>
    </xsl:template>
    
    <xsl:template match="nws:newsItem">
<div class="newsitem">
        <h3><xsl:value-of select="nws:title"/></h3>
        <p>Posted at: <xsl:value-of select="concat(substring(nws:insertDateTime,6,2),'/',substring(nws:insertDateTime,9,2),'/',substring(nws:insertDateTime,1,4),' ',substring(nws:insertDateTime,12,8))"/></p>
        <p class="newscontent"><xsl:apply-templates select="nws:content"/></p>
        <p class="to-top">
			 <a href="#content">Return to top</a><br/>
			 <a class="to-menu" href="#nav">Return to menu</a>
		</p>
</div>
    </xsl:template>
    
    <xsl:template match="nws:content">
            <xsl:apply-templates/>
    </xsl:template>
    
    <xsl:template match="nws:content//nws:subtitle">
        <h3>
            <xsl:value-of select="." />
        </h3>
    </xsl:template>
    
    <xsl:template match="nws:content//nws:newsImage">
        <p><img src="{nws:path}" class="auralNotRead" alt="{nws:imgDescription}" height="{@imgHeight}" width="{@imgWidth}" /></p>
    </xsl:template>
    
    <xsl:template match="nws:content//nws:newsLink">
        <a href="{nws:to}" title="{nws:title}"><xsl:value-of select="nws:text"/></a>
    </xsl:template>
    
    <xsl:template match="nws:content//text()">
        <xsl:copy-of select="." />
    </xsl:template>
    
</xsl:stylesheet>
